package goods

import (
	"encoding/json"
	"fmt"
	"github.com/martini-contrib/render"
	"net/http"
	"server/lib/Imartini"
	"server/lib/session"
	"server/web/model/shop/admin/goods"
)

func index(r render.Render, res http.ResponseWriter, req *http.Request, mlog *Imartini.Mlog, sess session.SESS) {
	// sess := session.GetAll(req)
	var info map[string]interface{}
	json.Unmarshal([]byte(sess["admin_info"]), &info)

	// mlog.Printf("%v", info["id"])

	r.HTML("shop/admin/goods/index.html", map[string]interface{}{
		"request": req,
	})
}

func goodsinfo(r render.Render, res http.ResponseWriter, req *http.Request, mlog *Imartini.Mlog, sess session.SESS) {
	// sess := session.GetAll(req)
	var info map[string]interface{}
	json.Unmarshal([]byte(sess["admin_info"]), &info)

	class := goods.Class(info["id"].(string))
	r.HTML("shop/admin/goods/goodsinfo.html", map[string]interface{}{
		"class": class,
	})
}

func addgoods(r render.Render, res http.ResponseWriter, req *http.Request, g Imartini.G, sess session.SESS) {
	image, _ := json.Marshal(req.Form["image[]"])
	data := map[string]string{
		"goodsname":  req.FormValue("goodsname"),
		"upperid":    req.FormValue("upperid"),
		"goodstitle": req.FormValue("goodstitle"),
		"sn":         req.FormValue("sn"),
		"price":      req.FormValue("price"),
		"vprice":     req.FormValue("vprice"),
		"oprice":     req.FormValue("oprice"),
		"kc":         req.FormValue("kc"),
		"remark":     req.FormValue("remark"),
		"isground":   req.FormValue("isground"),
		"isline":     req.FormValue("isline"),
		"text":       req.FormValue("text"),
		"image":      string(image),
		"attribute":  req.FormValue("attribute"),
	}
	fmt.Println(data)
	g["MSG"] = append(g["MSG"].([]string), fmt.Sprintf("%v", data))

}
